package com.runvp.service.biz.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.runvp.common.core.text.Convert;
import com.runvp.common.utils.DateUtils;
import com.runvp.service.biz.domain.BizPayRecord;
import com.runvp.service.biz.mapper.BizPayRecordMapper;
import com.runvp.service.biz.service.IBizPayRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 支付请求记录Service业务层处理
 * 
 * @author runvp
 * @date 2023-05-25
 */
@Service
public class BizPayRecordServiceImpl implements IBizPayRecordService {
    @Autowired
    private BizPayRecordMapper bizPayRecordMapper;


    /**
     * 保存支付记录
     * @param json
     */
    @Override
    public void savePayRecord(JSONObject json){
        BizPayRecord record = new BizPayRecord();
        record.setReferTime(new Date());
        record.setCreateBy(json.getString("createBy"));
        record.setItfType(json.getString("tranType"));
        record.setOrderNo(json.getString("orderNo"));
        record.setPayType(json.getString("payType"));
        record.setReqUrl(json.getString("reqUrl"));
        record.setPayId(json.getString("id"));
        record.setAmount(json.getString("pay_amt"));
        record.setPayOrderNo(json.getString("order_no"));
        record.setResStatus(json.getString("status"));
        record.setResData(json.toJSONString());
        insertBizPayRecord(record);
    }
    /**
     * 查询支付请求记录
     * 
     * @param id 支付请求记录主键
     * @return 支付请求记录
     */
    @Override
    public BizPayRecord selectBizPayRecordById(Long id) {
        return bizPayRecordMapper.selectBizPayRecordById(id);
    }
    /**
     * 查询支付请求记录
     *
     * @param orderNo
     * @return 支付请求记录
     */
    @Override
    public BizPayRecord selectBizPayRecordByOrderNo(String orderNo){
        return bizPayRecordMapper.selectBizPayRecordByOrderNo(orderNo);
    }
    /**
     * 查询支付请求记录列表
     * 
     * @param bizPayRecord 支付请求记录
     * @return 支付请求记录
     */
    @Override
    public List<BizPayRecord> selectBizPayRecordList(BizPayRecord bizPayRecord) {
        return bizPayRecordMapper.selectBizPayRecordList(bizPayRecord);
    }

    /**
     * 新增支付请求记录
     * 
     * @param bizPayRecord 支付请求记录
     * @return 结果
     */
    @Override
    public int insertBizPayRecord(BizPayRecord bizPayRecord) {
        bizPayRecord.setCreateTime(DateUtils.getNowDate());
        return bizPayRecordMapper.insertBizPayRecord(bizPayRecord);
    }

    /**
     * 修改支付请求记录
     * 
     * @param bizPayRecord 支付请求记录
     * @return 结果
     */
    @Override
    public int updateBizPayRecord(BizPayRecord bizPayRecord) {
        return bizPayRecordMapper.updateBizPayRecord(bizPayRecord);
    }

    /**
     * 批量删除支付请求记录
     * 
     * @param ids 需要删除的支付请求记录主键
     * @return 结果
     */
    @Override
    public int deleteBizPayRecordByIds(String ids) {
        return bizPayRecordMapper.deleteBizPayRecordByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除支付请求记录信息
     * 
     * @param id 支付请求记录主键
     * @return 结果
     */
    @Override
    public int deleteBizPayRecordById(Long id) {
        return bizPayRecordMapper.deleteBizPayRecordById(id);
    }
}
